package com.gtr.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class FillHandler implements MetaObjectHandler { //统一处理createTime、updateTime
    @Override
    public void insertFill(MetaObject metaObject) { //进行添加操作时自动调用该方法来设置Time
        this.setFieldValByName("createTime", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) { //进行更新操作时自动调用该方法来更新updateTime
        this.setFieldValByName("updateTime", LocalDateTime.now(), metaObject);
    }
}
